package com.sky.rabc.config;

import com.sky.rabc.Interceptor.MethodInterceptor;
import com.sky.rabc.Interceptor.TokenInterceptor;
import com.sky.rabc.Interceptor.UserPermissionInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
    private final UserPermissionInterceptor userPermissionInterceptor;
    private final TokenInterceptor tokenInterceptor;
    private final MethodInterceptor methodInterceptor;

    public WebConfig(UserPermissionInterceptor userPermissionInterceptor, TokenInterceptor tokenInterceptor, MethodInterceptor methodInterceptor) {
        this.userPermissionInterceptor = userPermissionInterceptor;
        this.tokenInterceptor = tokenInterceptor;
        this.methodInterceptor = methodInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**").excludePathPatterns("/back-user/login").excludePathPatterns("/order/*").excludePathPatterns("/order/test/*");
        registry.addInterceptor(userPermissionInterceptor).addPathPatterns("/**").excludePathPatterns("/back-user/login").excludePathPatterns("/order/*").excludePathPatterns("/order/test/*");
        registry.addInterceptor(methodInterceptor).addPathPatterns("/**");
    }
}
